home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kiconeffect.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  7.0 KB  |  231 lines

  1. /* vi: ts=8 sts=4 sw=4
  2.  *
  3.  * This file is part of the KDE project, module kdecore.
  4.  * Copyright (C) 2000 Geert Jansen <jansen@kde.org>
  5.  * with minor additions and based on ideas from
  6.  * Torsten Rahn <torsten@kde.org>
  7.  *
  8.  * This is free software; it comes under the GNU Library General
  9.  * Public License, version 2. See the file "COPYING.LIB" for the
  10.  * exact licensing terms.
  11.  */
  12.  
  13. #ifndef __KIconEffect_h_Included__
  14. #define __KIconEffect_h_Included__
  15.  
  16. #include <qimage.h>
  17. #include <qpixmap.h>
  18. #include <qcolor.h>
  19. #include <qrect.h>
  20. #include "kdelibs_export.h"
  21.  
  22. class QWidget;
  23.  
  24. class KIconEffectPrivate;
  25.  
  26. /**
  27.  * Applies effects to icons.
  28.  *
  29.  * This class applies effects to icons depending on their state and
  30.  * group. For example, it can be used to make all disabled icons
  31.  * in a toolbar gray.
  32.  * @see KIcon
  33.  */
  34. class KDECORE_EXPORT KIconEffect
  35. {
  36. public:
  37.   /**
  38.    * Create a new KIconEffect.
  39.    */
  40.     KIconEffect();
  41.     ~KIconEffect();
  42.  
  43.     /**
  44.      * This is the enumeration of all possible icon effects.
  45.      * Note that 'LastEffect' is no valid icon effect but only
  46.      * used internally to check for invalid icon effects.
  47.      *
  48.      * @li NoEffect: Don't apply any icon effect
  49.      * @li ToGray: Tints the icon gray
  50.      * @li Colorize: Tints the icon with an other color
  51.      * @li ToGamma: Change the gamma value of the icon
  52.      * @li DeSaturate: Reduce the saturation of the icon
  53.      * @li ToMonochrome: Produces a monochrome icon
  54.      */
  55.     enum Effects { NoEffect, ToGray, Colorize, ToGamma, DeSaturate,
  56.                    ToMonochrome,   ///< @since 3.4
  57.            LastEffect };
  58.  
  59.     /**
  60.      * Rereads configuration.
  61.      */
  62.     void init();
  63.  
  64.     /**
  65.      * Tests whether an effect has been configured for the given icon group.
  66.      * @param group the group to check, see KIcon::Group
  67.      * @param state the state to check, see KIcon::States
  68.      * @returns true if an effect is configured for the given @p group
  69.      * in @p state, otherwise false.
  70.      * @see KIcon::Group
  71.      * KIcon::States
  72.      */
  73.     bool hasEffect(int group, int state) const;
  74.  
  75.     /**
  76.      * Returns a fingerprint for the effect by encoding
  77.      * the given @p group and @p state into a QString. This
  78.      * is useful for caching.
  79.      * @param group the group, see KIcon::Group
  80.      * @param state the state, see KIcon::States
  81.      * @return the fingerprint of the given @p group+@p state
  82.      */
  83.      QString fingerprint(int group, int state) const;
  84.  
  85.     /**
  86.      * Applies an effect to an image. The effect to apply depends on the
  87.      * @p group and @p state parameters, and is configured by the user.
  88.      * @param src The image.
  89.      * @param group The group for the icon, see KIcon::Group
  90.      * @param state The icon's state, see KIcon::States
  91.      * @return An image with the effect applied.
  92.      */
  93.     QImage apply(QImage src, int group, int state) const;
  94.  
  95.     /**
  96.      * Applies an effect to an image.
  97.      * @param src The image.
  98.      * @param effect The effect to apply, one of KIconEffect::Effects.
  99.      * @param value Strength of the effect. 0 <= @p value <= 1.
  100.      * @param rgb Color parameter for effects that need one.
  101.      * @param trans Add Transparency if trans = true.
  102.      * @return An image with the effect applied.
  103.      */
  104.     // KDE4: make them references
  105.     QImage apply(QImage src, int effect, float value, const QColor rgb, bool trans) const;
  106.     /**
  107.      * @since 3.4
  108.      */
  109.     QImage apply(QImage src, int effect, float value, const QColor rgb, const QColor rgb2, bool trans) const;
  110.  
  111.     /**
  112.      * Applies an effect to a pixmap.
  113.      * @param src The pixmap.
  114.      * @param group The group for the icon, see KIcon::Group
  115.      * @param state The icon's state, see KIcon::States
  116.      * @return A pixmap with the effect applied.
  117.      */
  118.     QPixmap apply(QPixmap src, int group, int state) const;
  119.  
  120.     /**
  121.      * Applies an effect to a pixmap.
  122.      * @param src The pixmap.
  123.      * @param effect The effect to apply, one of KIconEffect::Effects.
  124.      * @param value Strength of the effect. 0 <= @p value <= 1.
  125.      * @param rgb Color parameter for effects that need one.
  126.      * @param trans Add Transparency if trans = true.
  127.      * @return A pixmap with the effect applied.
  128.      */
  129.     QPixmap apply(QPixmap src, int effect, float value, const QColor rgb, bool trans) const;
  130.     /**
  131.      * @since 3.4
  132.      */
  133.     QPixmap apply(QPixmap src, int effect, float value, const QColor rgb, const QColor rgb2, bool trans) const;
  134.  
  135.     /**
  136.      * Returns an image twice as large, consisting of 2x2 pixels.
  137.      * @param src the image.
  138.      * @return the scaled image.
  139.      */
  140.     QImage doublePixels(QImage src) const;
  141.  
  142.     /**
  143.      * Provides visual feedback to show activation of an icon on a widget.
  144.      *
  145.      * Not strictly an 'icon effect', but in practice that's what it looks
  146.      * like.
  147.      *
  148.      * This method does nothing if the global 'Visual feedback on activation'
  149.      * option is not activated (See kcontrol/Peripherals/Mouse).
  150.      *
  151.      * @param widget The widget on which the effect should be painted
  152.      * @param rect This rectangle defines the effect's borders
  153.      */
  154.     static void visualActivate(QWidget *widget, QRect rect);
  155.  
  156.     /**
  157.      * Tints an image gray.
  158.      *
  159.      * @param image The image
  160.      * @param value Strength of the effect. 0 <= @p value <= 1
  161.      */
  162.     static void toGray(QImage &image, float value);
  163.  
  164.     /**
  165.      * Colorizes an image with a specific color.
  166.      *
  167.      * @param image The image
  168.      * @param col The color with which the @p image is tinted
  169.      * @param value Strength of the effect. 0 <= @p value <= 1
  170.      */
  171.     static void colorize(QImage &image, const QColor &col, float value);
  172.  
  173.     /**
  174.      * Produces a monochrome icon with a given foreground and background color
  175.      *
  176.      * @param image The image
  177.      * @param white The color with which the white parts of @p image are painted
  178.      * @param black The color with which the black parts of @p image are painted
  179.      * @param value Strength of the effect. 0 <= @p value <= 1
  180.      * @since 3.4
  181.      */
  182.     static void toMonochrome(QImage &image, const QColor &black, const QColor &white, float value);
  183.  
  184.     /**
  185.      * Desaturates an image.
  186.      *
  187.      * @param image The image
  188.      * @param value Strength of the effect. 0 <= @p value <= 1
  189.      */
  190.     static void deSaturate(QImage &image, float value);
  191.  
  192.     /**
  193.      * Changes the gamma value of an image.
  194.      *
  195.      * @param image The image
  196.      * @param value Strength of the effect. 0 <= @p value <= 1
  197.      */
  198.     static void toGamma(QImage &image, float value);
  199.  
  200.     /**
  201.      * Renders an image semi-transparent.
  202.      *
  203.      * @param image The image
  204.      */
  205.     static void semiTransparent(QImage &image);
  206.  
  207.     /**
  208.      * Renders a pixmap semi-transparent.
  209.      *
  210.      * @param pixmap The pixmap
  211.      */
  212.     static void semiTransparent(QPixmap &pixmap);
  213.  
  214.     /**
  215.      * Overlays an image with an other image.
  216.      *
  217.      * @param src The image
  218.      * @param overlay The image to overlay @p src with
  219.      */
  220.     static void overlay(QImage &src, QImage &overlay);
  221.  
  222. private:
  223.     int mEffect[6][3];
  224.     float mValue[6][3];
  225.     QColor mColor[6][3];
  226.     bool mTrans[6][3];
  227.     KIconEffectPrivate *d;
  228. };
  229.  
  230. #endif
  231.